/*
 * MenuItem.java
 *
 * Created on 2004-08-28 00:00:00 +0900 (Sat, 28 Aug 2004)
 *
 * $Revision: 33 $
 * $Date: 2008-07-27 15:31:44 +0000 (Sun, 27 Jul 2008) $
 */

package org.gikolet.framework.ui;

import java.util.Vector;

import org.gikolet.framework.ui.events.ActionEvent;
import org.gikolet.framework.ui.events.ActionListener;

/**
 * @author Tetsutaro (latest modification by $Author: tetsutaro.ss $)
 * @version $Revision: 33 $ $Date: 2008-07-27 15:31:44 +0000 (Sun, 27 Jul 2008) $
 */
public class MenuItem {
    private String label;
    private Menu parent;

    private Vector _listeners;

    public MenuItem(String label) {
	if (label == null) {
	    label = "";
	}
	this.label = label;
    }

    public String getLabel() {
	return this.label;
    }

    public Menu getParent() {
	return this.parent;
    }

    void setParent(Menu parent) {
	this.parent = parent;
    }

    public void addActionListener(ActionListener listener) {
	if (_listeners == null) {
	    _listeners = new Vector();
	}
	_listeners.addElement(listener);
    }

    public void removeActionListener(ActionListener listener) {
	_listeners.removeElement(listener);
    }

    protected void fireAction() {
	if (_listeners == null) {
	    return;
	}

	ActionEvent e = null;
	for (int i = 0; i < _listeners.size(); i++) {
	    if (e == null) {
		e = new ActionEvent(this, "MenuItemAction");
	    }
	    ((ActionListener) _listeners.elementAt(i)).actionPerformed(e);
	}
    }

    public String toString() {
	return label;
    }
}
